<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Pages extends Controller_App {

    public $page = 'index';
    public $template = 'template';

    public function before() {
        $this->page = Request::initial()->param('page', $this->page);

        $this->page = ORM::factory('page')
                ->where('page', '=', $this->page)
                ->where('lang', '=', self::getLang())
                ->find();
        
        if ($this->page->loaded())
            $this->template = $this->page->template;
        else {
            $this->page->title = "Error 404";
            $this->page->content = "<p>&raquo; Page not found...</p>";
        }

        parent::before();
    }

    public function action_index() {
        $this->template->page_title = $this->page->title;
        $this->template->page_content = $this->page->content;
    }

}